﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_ABOVEBELOWMKTRATE
    {
        public DataTable SearchAll(AboveBelowMktRate above, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));

                lstParams.Add(new SqlParameter("@TransactionDate", above.TransactionDate));
                lstParams.Add(new SqlParameter("@MarketCode", above.MarketCode));
                dt = Utility.StoredProcDataTable("SPR_ABOVEBELOWMKTRATE_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int AboveBelowMktRateID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@AboveBelowMktRateID", AboveBelowMktRateID));
                dt = Utility.StoredProcDataTable("SPR_ABOVEBELOWMKTRATE_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(AboveBelowMktRate above)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@AboveBelowMktRateID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", above.TransactionDate));
                lstParams.Add(new SqlParameter("@MarketCode", above.MarketCode));
                lstParams.Add(new SqlParameter("@IsFixedRate", above.IsFixedRate));
                lstParams.Add(new SqlParameter("@FixedRate", above.FixedRate));
                lstParams.Add(new SqlParameter("@ReferenceInterestCD", above.ReferenceInterestCD));
                lstParams.Add(new SqlParameter("@RatioAdjustment", above.RatioAdjustment));
                lstParams.Add(new SqlParameter("@IsConfirmed", above.IsConfirmed));
                lstParams.Add(new SqlParameter("@CreatedDate", above.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", above.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", above.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", above.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", above.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", above.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", above.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", above.UpdatedBranch));

                Utility.ExecuteStoredProc("SPR_ABOVEBELOWMKTRATE_INSERT", lstParams.ToArray());
                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(AboveBelowMktRate above)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@AboveBelowMktRateID", above.AboveBelowMktRateID));
                lstParams.Add(new SqlParameter("@TransactionDate", above.TransactionDate));
                lstParams.Add(new SqlParameter("@MarketCode", above.MarketCode));
                lstParams.Add(new SqlParameter("@IsFixedRate", above.IsFixedRate));
                lstParams.Add(new SqlParameter("@FixedRate", above.FixedRate));
                lstParams.Add(new SqlParameter("@ReferenceInterestCD", above.ReferenceInterestCD));
                lstParams.Add(new SqlParameter("@RatioAdjustment", above.RatioAdjustment));
                lstParams.Add(new SqlParameter("@IsConfirmed", above.IsConfirmed));
                lstParams.Add(new SqlParameter("@UpdatedDate", above.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", above.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", above.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", above.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_ABOVEBELOWMKTRATE_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(AboveBelowMktRate above)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@AboveBelowMktRateID", above.AboveBelowMktRateID));
                lstParams.Add(new SqlParameter("@UpdatedDate", above.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", above.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", above.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", above.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ABOVEBELOWMKTRATE_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
